"""
    登录验证
    @author tina
    @since 2023-10-09 00:17:31
"""

from flask import Blueprint, request
from aiapp import setting

from aiapp.utils import r_result as r, login_util

logger = setting.log_config.logger

bp = Blueprint('login', __name__)


@bp.route('send_verification_code', methods=['POST'])
def send_verification_code():
    """
        发送邮件验证码
    :return: bool
    """
    param = request.get_json()
    logger.debug('param:{}', param)
    mail = param.get('mail')
    flag = login_util.send_verification_code(mail)
    return r.success_response_data(flag)


@bp.route('verify', methods=['POST'])
def login_verify():
    """登录验证"""
    param = request.get_json()
    logger.debug('param:{}', param)
    code = param.get('code')
    mail = param.get('mail')

    if code is None or code == '' or mail is None or mail == '':
        return r.missing_param()

    return r.success_response_data(login_util.auth_verification_code(code, mail))
